<?php

namespace app\common\model\xiluhouse;

use think\Model;
use traits\model\SoftDelete;

class SpecialLog extends Model
{

    use SoftDelete;

    // 表名
    protected $name = 'xiluhouse_special_log';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'page_type_text',
        'device_type_text',
        'state_text',
    ];

    public function getPageTypeList()
    {
        return ['wlsf' => __('Page_type wlsf'), 'hhmz' => __('Page_type hhmz'), 'hqsq' => __('Page_type hqsq'), 'hzy' => __('Page_type hzy'), 'detail' => __('Page_type detail')];
    }

    public function getDeviceTypeList()
    {
        return ['ios' => __('Device_type ios'), 'andriod' => __('Device_type andriod'), 'orther' => __('Device_type orther')];
    }

    public function getStateList()
    {
        return ['1' => __('State 1'), '2' => __('State 2'), '3' => __('State 3')];
    }

    public function getPageTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['page_type']) ? $data['page_type'] : '');
        $list = $this->getPageTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getDeviceTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['device_type']) ? $data['device_type'] : '');
        $list = $this->getDeviceTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getStateTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['state']) ? $data['state'] : '');
        $list = $this->getStateList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function house()
    {
        return $this->belongsTo('House', 'house_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function user()
    {
        return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
